
package com.sdkj.recruit.provider;

import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.annotate.JsonSerialize;

/**
 * 定制jackson的json序列化，过滤掉空和null的字�?
 * 
 * @author yaoyasong
 * @version 1.0 2015�?9�?9�?
 * @since 1.0
 */
public class SkipEmptyJacksonJsonProvider extends JacksonJsonProvider {

	@Override
	public void writeTo(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
			MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException {

		ObjectMapper mapper = locateMapper(type, mediaType);
		
		mapper.setSerializationConfig(mapper.getSerializationConfig().withSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY));
		
		super.writeTo(value, type, genericType, annotations, mediaType, httpHeaders, entityStream);
	}
}
